﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTcms.Web.UI;
using DTcms.Common;
using System.Data;
namespace DTcms.Web
{
    public partial class company_index : System.Web.UI.Page
    {
        private int company_id = 0;
        public string[] com = new string[20];
        public string companyabout = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            company_id = DTRequest.GetQueryInt("d");

            if (!IsPostBack)
            {
                //获取公司简介等
                BLL.company bll3 = new BLL.company();
                Model.company model = bll3.GetModel(company_id);
                //Response.Write(model.topimg);
                if (model != null)
                {
                    #region  绑定 banner 图
                    //绑定 banner 图
                    BLL.company_albums bllcomb = new BLL.company_albums();
                    DataSet ds8 = bllcomb.GetList(" company_id=" + company_id);

                    if (ds8.Tables[0].Rows.Count > 0)
                    {

                        company_banner.DataSource = ds8;
                        company_banner.DataBind();
                    }
                    else
                    {
                        DataTable dt = new DataTable();
                        DataColumn dc1 = new DataColumn("original_path", Type.GetType("System.String"));
                        dt.Columns.Add(dc1);
                        if (model.topimg + "" != "")
                        {
                            DataRow dr = dt.NewRow();
                            dr["original_path"] = "http://pic.shicaiquanzi.com" + model.topimg;
                            dt.Rows.Add(dr);
                        }
                        else
                        {
                            DataRow dr = dt.NewRow();
                            dr["original_path"] = "images/banner1.jpg";
                            dt.Rows.Add(dr);
                        }
                        //Response.Write(dt.Rows.Count);
                        company_banner.DataSource = dt;
                        company_banner.DataBind();
                    }
                    #endregion

                    #region 绑定公司基本信息
                    string logo = "";
                    if (model.logo + "" != "")
                    {
                        if (model.logo.Contains("shicaiquanzi"))
                        {
                            if (model.logo.Contains("http://")) { logo = model.logo; }
                            else { logo = "http://" + model.logo; }
                        }
                        else
                        {
                            logo = "http://pic.shicaiquanzi.com" + model.logo;
                        }
                    }
                    com[0] = logo;
                    com[1] = model.title;
                    if (model.pro_remark.Length > 50)
                    {
                        com[2] = DTcms.Common.Utils.DropHTML(model.pro_remark).Substring(0, 50)+"...";
                    }
                    else {
                        com[2] = DTcms.Common.Utils.DropHTML(model.pro_remark);
                    }
                    //com[2] = model.pro_remark;
                    if (model.video_img + "" != "")
                    {

                        com[3] = "http://pic.shicaiquanzi.com" + model.video_img;
                    }
                    else { com[3] = ""; }

                    if (model.video_url + "" != "")
                    {

                        com[4] = "http://pic.shicaiquanzi.com" + model.video_url;
                    }
                    else { com[4] = ""; }
                    string _aboutcompany = DTcms.Common.Utils.DropHTML(model.about);

                    if (_aboutcompany.Length > 200)
                    {
                        _aboutcompany = _aboutcompany.Substring(0, 200);
                    }
                    com[6] = _aboutcompany + "...";
                    companyabout = DTcms.Common.Utils.DropHTML(model.about);
                    com[7] = model.lianxiren;
                    com[8] = model.address;

                    if (!string.IsNullOrEmpty(model.topimg))
                    {
                        com[11] = "\"http://pic.shicaiquanzi.com" + model.address;
                    }
                    else
                    {
                        com[11] = "";
                    }
                    com[12] = model.mobile;
                    #endregion

                    #region  ///产品 列表 com[5]
                    ///产品 列表
                    //获取求购信息
                    BLL.product bll1 = new BLL.product();
                    DataSet ds1 = bll1.GetList(9, "status=1 and company_id=" + company_id, " add_time desc");
                    //如果记录存在
                    if (ds1.Tables[0].Rows.Count > 0)
                    {


                        for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                        {
                            DataRow dr = ds1.Tables[0].Rows[i];
                            string proimg = dr["img_url"].ToString();
                            string img_url = "";
                            if (proimg.Contains("shicaiquanzi"))
                            {
                                if (proimg.Contains("http://")) { img_url = proimg; }
                                else { img_url = "http://" + proimg; }
                            }
                            else
                            {
                                img_url = "http://pic.shicaiquanzi.com" + proimg;
                            }


                            com[5] += "<li class=\"col-md-3 \">";
                            com[5] += "<a href=\"" + img_url + "\" class=\"spotlight\"><img src = \"" + img_url + "\"/></a>";
                            com[5] += "<h2>" + dr["title"] + "</h2>";
                            com[5] += "</li>";
                        }
                    }
                    else
                    {
                        com[5] = "";
                    }
                    #endregion


                    #region  ///相册 列表 com[9]
                    ///产品 列表
                    //获取求购信息
                    BLL.xiangce bll5 = new BLL.xiangce();
                    DataSet ds5 = bll5.GetList(9, "company_id=" + company_id, "sort_id desc,add_time desc");
                    //如果记录存在
                    if (ds5.Tables[0].Rows.Count > 0)
                    {

                        for (int i = 0; i < ds5.Tables[0].Rows.Count; i++)
                        {
                            DataRow dr = ds5.Tables[0].Rows[i];
                            string proimg = dr["img_url"].ToString();
                            string img_url = "";
                            if (proimg.Contains("shicaiquanzi"))
                            {
                                if (proimg.Contains("http://")) { img_url = proimg; }
                                else { img_url = "http://" + proimg; }
                            }
                            else
                            {
                                img_url = "http://pic.shicaiquanzi.com" + proimg;
                            }


                            com[9] += "<li class=\"col-md-3 \">";
                            com[9] += "<a href=\""+ img_url + "\" class=\"spotlight\"><img src = \"" + img_url + "\"/></a>";
                            com[9] += "<h2>" + dr["title"] + "</h2>";
                            com[9] += "</li>";
                        }
                    }
                    else
                    {
                        com[9] = "";
                    }
                    #endregion

                    #region   //获取最新动态 com[10]
                    //获取最新动态
                    BLL.xinxi bll = new BLL.xinxi();

                    DataSet ds = bll.GetList(9, "status < 2  and company_id = " + company_id, "id desc");
                    //如果记录存在
                    if (ds.Tables[0].Rows.Count > 0)

                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            DataRow dr3 = ds.Tables[0].Rows[i];
                            string proimg = dr3["img_url"].ToString();
                            string img_url = "";

                            string _username = new BLL.users().GetUserName(Convert.ToInt32(dr3["user_id"]));
                            string _avatar = new BLL.users().GetAvatar(Convert.ToInt32(dr3["user_id"]));
                            if (_avatar.Contains("shicaiquanzi"))
                            {
                                if (_avatar.Contains("http://")) { img_url = _avatar; }
                                else { img_url = "http://" + _avatar; }
                            }
                            else
                            {
                                img_url = "http://pic.shicaiquanzi.com" + _avatar;
                            }

                            com[10] += "<li class=\"col-md-6\" >";
                            com[10] += "<div class=\"top\">";
                            com[10] += "<div class=\"top_left\"><em><img src=\"" + img_url + "\"/></em></div>";
                            com[10] += "<div class=\"top_right\"><p>" + _username + "</p><p><span class=\"num" + dr3["type_id"] + "\">" + new BLL.xinxi_type().GetTitle(Convert.ToInt32(dr3["type_id"])) + "</span> 发布于：" + Utils.DateStringFromNow(Convert.ToDateTime(dr3["add_time"])) + "</p></div>";
                            com[10] += "</div>";
                            com[10] += "<div class=\"remark\">" + dr3["content"].ToString() + "</div>";

                            BLL.xinxi_albums pbll = new BLL.xinxi_albums();
                            DataSet pds = pbll.GetLists(int.Parse(dr3["id"].ToString()));
                            if (pds.Tables[0].Rows.Count > 0)
                            {
                                com[10] += "<div class=\"pic_list\">";
                                for (int ii = 0; ii < pds.Tables[0].Rows.Count; ii++)
                                {
                                    DataRow pdr = pds.Tables[0].Rows[ii];
                                    string picurl = pdr["thumb_path"].ToString();
                                    string _picurl = "";
                                    if (picurl.Contains("http://"))
                                    {
                                        _picurl = picurl;
                                    }
                                    else
                                    {
                                        _picurl = "http://" + picurl;
                                    }
                                    com[10] += "<div class=\"pic\"><img src='" + _picurl + "'/></div>";
                                }
                                com[10] += "</div>";
                            }
                            com[10] += "</li>";
                        }
                }
                else
                {
                    com[10] = "";
                }
                #endregion
            }

        }
    }
}